package me.ilich.piet.interpreter;

import me.ilich.piet.interpreter.commands.Command;


public class StackImpl implements Stack {

	private final StackState mStackState = new StackState();

	private final Context mStackContext = new ContextImpl();

	private OnStateListener mOnStateListener;
	private OnInListener mOnInListener;
	private OnOutListener mOnOutListener;

	@Override
	public void execute(Command command) {
		command.onExecute(mStackContext);
	}

	@Override
	public void setOnStateListener(OnStateListener listener) {
		mOnStateListener = listener;
	}

	@Override
	public void setOnInListener(OnInListener listener) {
		mOnInListener = listener;
	}

	@Override
	public void setOnOutListener(OnOutListener listener) {
		mOnOutListener = listener;
	}

	StackState getStackState() {
		return mStackState;
	}

	private class ContextImpl implements Context {

		@Override
		public StackState getStackState() {
			return mStackState;
		}

		@Override
		public OnStateListener getOnStateListener() {
			return mOnStateListener;
		}

		@Override
		public OnInListener getOnInListener() {
			return mOnInListener;
		}

		@Override
		public OnOutListener getOnOutListener() {
			return mOnOutListener;
		}

	}

}
